package org.fenixsoft.jvm.chapter12;

/**
 * 标准的双锁检测（Double Check Lock，DCL）单例代码
 */
public class Singleton {
    private volatile static Singleton instance;
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton(); //volatile使其他线程立即可见instance的值
                }
            }
        }
        return instance;
    }
}
